package com.cn.qgx428.lazydiary.dialog

import android.app.Dialog
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import android.widget.FrameLayout
import android.widget.LinearLayout
import com.cn.qgx428.lazydiary.R
import kotlinx.android.synthetic.main.dialog_custom_alert.*
import kotlinx.android.synthetic.main.dialog_input.*

/**
 * Created by qinguanxiong on 2018/3/12.
 */
class InputDialog : Dialog {

    lateinit var mContext: Context
    lateinit var mainView: View

    constructor(context: Context): super(context){
        mContext = context
        mainView = LayoutInflater.from(mContext).inflate(R.layout.dialog_input,null)
        setContentView(mainView)
        initView()
    }

    private fun initView() {
        // 调整背景大小
        val wm = mContext.getSystemService(Context.WINDOW_SERVICE) as WindowManager
        val display = wm.defaultDisplay
        dialog_input_mainLayout.layoutParams =
                FrameLayout.LayoutParams(((display.width * 0.75).toInt()),
                        LinearLayout.LayoutParams.WRAP_CONTENT)
        dialogInput_cancel.setOnClickListener({ dismiss() })
    }

    public fun setCommit(listener: (msg: String)->Unit){
        dialogInput_commit.setOnClickListener({
            listener(dialogInput_tex.text.toString())
            dismiss()
        })
    }
}